from django.shortcuts import render_to_response
from django.template.context import RequestContext
from models import TipoMatConsumo
from forms import TipoMatConsumoForm


def listaTipo(request):
    lista_tipos = TipoMatConsumo.objects.all()
    return render_to_response("listaTipo.html",
                              {'lista_tipos':lista_tipos})

def menu (request):
    return render_to_response("mat/okay.html", context_instance=RequestContext(request),)


def addTipo(request):
    if request.method == 'POST':
        form = TipoMatConsumoForm(request.POST, request.FILES)
        if form.is_valid():
            dados = form.cleaned_data
            item = TipoMatConsumo(descricao=dados['tipoMat'])
            item.save()
            return render_to_response("mat/okay.html", {})
        
    else:
        form = TipoMatConsumoForm()
    return render_to_response("mat/add.html", {'form':form}, context_instance=RequestContext(request))